package com.sc.VenusQueryBeta.presenter.vip;

import com.hengjun.kingstar.sdk.utils.LogUtils;
import com.sc.VenusQueryBeta.contract.vip.VipUserContract;
import com.sc.VenusQueryBeta.model.bean.account.List;
import com.sc.VenusQueryBeta.model.bean.login.QueryRegisBean;
import com.sc.VenusQueryBeta.model.vip.VipUserModel;

import io.reactivex.functions.Consumer;

/**
 * Created by SC-02 on 2018/9/19.
 * vip用户presenter 继承契约类的presenper
 */
public class VipUserPresenter extends VipUserContract.VipUserPresenter {


    @Override
    protected VipUserContract.IVipModel getModel() {
        return VipUserModel.newInstance();
    }

    @Override
    public void onStart() {

    }

    /**
     * 实例化
     * @return 提供对象给外界
     */
    public static VipUserPresenter newInstance(){
        return new VipUserPresenter();
    }


    @Override
    public void queryRegisterServerSetting(String id) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.queryRegisterServerSetting(id).subscribe(new Consumer<QueryRegisBean>() {
            @Override
            public void accept(QueryRegisBean queryRegisBean) throws Exception {
                if (mIView != null)
                    mIView.showQueryRegisBeanDataSuccess(queryRegisBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                if (mIView != null) {
                    if (mIView.isVisiable())
                        LogUtils.e("錯愕error00=="+throwable.getMessage());
                    mIView.showToast("Network error"+throwable.getMessage());
                    mIView.showNetworkError();
                }
            }
        }));
    }

    //查询子户口
    @Override
    public void queryAccountList(String serverAddress, String projectName, int serverPort, String loginBeanId) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.queryAccountList(serverAddress,projectName,serverPort,loginBeanId).subscribe(new Consumer<List>() {
            @Override
            public void accept(List accountAccountListBean) throws Exception {
                if (mIView != null)
                    mIView.showAccountListDataSuccess(accountAccountListBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e("queryAccountList錯愕error="+throwable.getMessage());
                if (mIView != null) {
                    if (mIView.isVisiable())
                        mIView.showToast("Network error"+throwable.getMessage());
                    mIView.showNetworkError();
                }
            }
        }));
    }

    @Override
    public void queryRegistPassword(int clientindex, String serverSettingIndex) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.queryRegistPassword(clientindex,serverSettingIndex).subscribe(new Consumer<String>() {
            @Override
            public void accept(String queryRegistPasswordBean) throws Exception {
                if (mIView != null)
                    mIView.queryRegistPasswordBean(queryRegistPasswordBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e("錯愕error11="+throwable.getMessage());
                if (mIView != null) {
                    if (mIView.isVisiable())
                        mIView.showToast("Network error");
                    mIView.showNetworkError();
                }
            }
        }));
    }

    /**
     *发送验证码
     * @param clientindex
     */
    @Override
    public void sendcode(int clientindex) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.sendcode(clientindex).subscribe(new Consumer<String>() {
            @Override
            public void accept(String sendcodeBean) throws Exception {
                if (mIView != null)
                    mIView.sendcodeBean(sendcodeBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e("錯愕error="+throwable.getMessage());
                if (mIView != null) {
                    if (mIView.isVisiable())
                        mIView.showToast("Network error:"+throwable.getMessage());
                    mIView.showNetworkError();
                }
            }
        }));
    }

    @Override
    public void sethukoupwd(String clientindex, String verificaCode, String smsQueryPassword, String serverSettingIndex) {

    }

    /**
     * 設置戶口密碼
     * @param clientindex
     * @param verificaCode
     * @param smsQueryPassword
     * @param serverSettingIndex
     */
    @Override
    public void sethukoupwd(int clientindex, String verificaCode, String smsQueryPassword, String serverSettingIndex) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.sethukoupwd(clientindex,verificaCode,smsQueryPassword,serverSettingIndex).subscribe(new Consumer<String>() {
            @Override
            public void accept(String sethukouBean) throws Exception {
                if (mIView != null)
                    mIView.sethukouBean(sethukouBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e("錯愕error="+throwable.getMessage());
                if (mIView != null) {
                    if (mIView.isVisiable())
                        mIView.showToast("Network error"+throwable.getMessage());
                    mIView.showNetworkError();
                }
            }
        }));
    }


    /**
     * //户口密码输入时查询密码正确
     * @param serverAddress
     * @param projectName
     * @param serverPort
     * @param smsQueryPassword
     * @param clientid
     */
    @Override
    public void conFirmPwd(String serverAddress, String projectName, int serverPort, String smsQueryPassword, String clientid) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.conFirmPwd(serverAddress,projectName,serverPort,smsQueryPassword,clientid).subscribe(new Consumer<String>() {
            @Override
            public void accept(String s) throws Exception {
                if (mIView != null)
                    mIView.conFirmPwdBean(s);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e("錯愕error="+throwable.getMessage());
                if (mIView != null) {
                    if (mIView.isVisiable())
                        mIView.showToast("Network error"+throwable.getMessage());
                    mIView.showNetworkError();
                }
            }
        }));
    }
}
